package com.jbinfo.qingcaowan.studyManager.service;

import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.bana.common.util.page.PageCond;
import org.bana.common.util.page.PageCondUtil;
import org.bana.common.util.page.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.jbinfo.common.utils.DataCommUtil;
import com.jbinfo.common.utils.DataTables;
import com.jbinfo.common.utils.DateUtils;
import com.jbinfo.common.utils.UUIDUtils;
import com.jbinfo.qingcaowan.base.dao.BaseSignDao;
import com.jbinfo.qingcaowan.base.dao.BaseTimeDao;
import com.jbinfo.qingcaowan.base.dto.BaseSignDTO;
import com.jbinfo.qingcaowan.base.dto.BaseTimeDTO;
import com.jbinfo.qingcaowan.base.entity.BaseTime;
import com.jbinfo.qingcaowan.common.BusinessException;
import com.jbinfo.qingcaowan.common.CheckParamUtil;
import com.jbinfo.qingcaowan.common.ClonePojoUtil;
import com.jbinfo.qingcaowan.common.JSONResult;
import com.jbinfo.qingcaowan.common.ExceptionConstants.BusinessExceptionCode;
import com.jbinfo.qingcaowan.exam.dao.CircleDao;
import com.jbinfo.qingcaowan.exam.dto.ExamCircleDTO;
import com.jbinfo.qingcaowan.security.entity.User;
import com.jbinfo.qingcaowan.studyManager.dao.BookManagerDao;
import com.jbinfo.qingcaowan.studyManager.dao.CardManagerDao;
import com.jbinfo.qingcaowan.studyManager.dao.CycleDetailDao;
import com.jbinfo.qingcaowan.studyManager.dao.CycleMainDao;
import com.jbinfo.qingcaowan.studyManager.dto.CycleDetailDTO;
import com.jbinfo.qingcaowan.studyManager.dto.CycleMainModel;
import com.jbinfo.qingcaowan.studyManager.dto.StudyCycleDTO;
import com.jbinfo.qingcaowan.studyManager.entity.BookCard;
import com.jbinfo.qingcaowan.studyManager.entity.BookInfo;
import com.jbinfo.qingcaowan.studyManager.entity.CycleDetail;
import com.jbinfo.qingcaowan.studyManager.entity.CycleMain;
import com.jbinfo.qingcaowan.studyManager.entity.CycleMainInfo;
import com.jbinfo.qingcaowan.studyManager.service.CycleMainService;
import com.jbinfo.qingcaowan.user.dao.ScoreDetailDAO;
import com.jbinfo.qingcaowan.user.dao.ScoreSetDAO;
import com.jbinfo.qingcaowan.user.dao.UserDao;
import com.jbinfo.qingcaowan.user.domain.ScoreDetailDomain;
import com.jbinfo.qingcaowan.user.dto.UserDTO;
import com.jbinfo.qingcaowan.user.service.OrgService;
/**
 * 
* @ClassName: CycleMainServiceImpl 
* @Description: TODO
* @author ZhangLei
* @date 2016年7月11日 上午11:02:55
 */
@Service("cycleMainService")
public class CycleMainServiceImpl implements CycleMainService {
	
	private static Logger log = LoggerFactory.getLogger(CycleMainServiceImpl.class);
	
	@Resource(name="cycleMainDao")
	private CycleMainDao cycleMainDao;
	@Resource(name="bookManagerDao")
	private BookManagerDao bookManagerDao;
	
	@Resource(name="cycleDetailDao")
	private CycleDetailDao cycleDetailDao;
	
	@Resource(name="baseTimeDao")
	private BaseTimeDao baseTimeDao;
	
	@Resource(name="cardManagerDao")
	private CardManagerDao cardManagerDao;
	
	@Resource(name="circleDao")
	private CircleDao circleDao;
	
	@Resource
	private OrgService orgService;
	
	@Resource(name="userDao")
	private UserDao userDao;
	
	@Resource(name="scoreSetDAO")
	private ScoreSetDAO scoreSetDAO;
	
	@Resource(name="scoreDetailDAO")
	private ScoreDetailDAO scoreDetailDAO;
	
	@Resource(name="baseSignDao")
	private BaseSignDao baseSignDao;
	
	/**
	 * 
	 * @Description: TODO 查询周期主表
	 * @author ZhangLei  
	 * @date 2016年7月11日 上午11:04:33 
	 * @param cycleMainModel
	 * @return 
	 * @see com.jbinfo.qingcaowan.studyManager.service.CycleMainService#findByParam(com.jbinfo.qingcaowan.studyManager.entity.CycleMainModel)
	 */
	@Override
	public DataTables<CycleMainInfo> findByParam(CycleMainModel cycleMainModel) {
		return DataTables.combinTotalRecords(cycleMainDao.findByParam(cycleMainModel));
	}
	/**
	 * 
	 * @Description: TODO 新建保存
	 * @author ZhangLei  
	 * @date 2016年7月12日 下午6:27:43 
	 * @param cycleMainInfo 
	 * @see com.jbinfo.qingcaowan.studyManager.service.CycleMainService#save(com.jbinfo.qingcaowan.studyManager.entity.CycleMainInfo)
	 */
	@Override
	public void save(CycleMainInfo cycleMainInfo) {
		CycleMain cycleMain = verification(cycleMainInfo, "create");
		
		cycleMain.setId(UUIDUtils.create());
		cycleMain.setValidateFlag("1");
		cycleMain.setCreateUser(cycleMainInfo.getCreateUser());
		cycleMain.setGmtCreate(new Date());
		cycleMainDao.insert(cycleMain);
	}
	/**
	 * 
	 * @Description: TODO 编辑更新
	 * @author ZhangLei  
	 * @date 2016年7月12日 下午6:27:48 
	 * @param cycleMainInfo 
	 * @see com.jbinfo.qingcaowan.studyManager.service.CycleMainService#edit(com.jbinfo.qingcaowan.studyManager.entity.CycleMainInfo)
	 */
	@Override
	public void edit(CycleMainInfo cycleMainInfo) {
		CycleMain cycleMain = verification(cycleMainInfo, "update");
		
		cycleMain.setModifiedUser(cycleMainInfo.getModifiedUser());
		cycleMain.setGmtModified(new Date());
		cycleMainDao.update(cycleMain);
	}
	/**
	 * 
	 * @Description: TODO 根据id获取信息
	 * @author ZhangLei  
	 * @date 2016年7月12日 下午6:27:54 
	 * @param id
	 * @return 
	 * @see com.jbinfo.qingcaowan.studyManager.service.CycleMainService#getById(java.lang.String)
	 */
	@Override
	public CycleMainInfo getById(String id) {
		return cycleMainDao.getById(id);
	}
	/**
	 * 
	* @Title: verification 
	* @Description: TODO 属性校验
	* @author ZhangLei  
	* @date 2016年7月12日 下午6:27:58 
	* @param @param cycleMainInfo
	* @param @param param
	* @param @return    设定文件 
	* @return CycleMain    返回类型 
	* @throws
	 */
	private CycleMain verification(CycleMainInfo cycleMainInfo, String param) {
		String id = cycleMainInfo.getId();
		if("update".equals(param)){
			if(id==null||"".equals(id)){
				throw new RuntimeException("周期ID不能为空;");
			}
			CycleMain cycleMainDB = (CycleMain) cycleMainDao.selectByPrimaryKey(id);
			if(cycleMainDB==null){
				throw new RuntimeException("周期不存在;");
			}
		}
		
		String bookId = cycleMainInfo.getBookId();
		BookInfo bookInfoDB = new BookInfo();
		if (bookId == null || "".equals(bookId)) {
			throw new RuntimeException("书籍ID为空！");
		}else {
			bookInfoDB = (BookInfo) bookManagerDao.findById(bookId);
			if(bookInfoDB==null){
				throw new RuntimeException("书籍不存在！");
			}
		}
		
		String orgId = cycleMainInfo.getOrgId();
		if(!(orgId==null||"".equals(orgId))){
			if(!orgId.equals(bookInfoDB.getOrgId())){
				throw new RuntimeException("所选组织与书籍所属组织不一致！");
			}
		}else{
			cycleMainInfo.setOrgId(bookInfoDB.getOrgId());
		}
		String startDateStr = cycleMainInfo.getStartDateStr();
		if(DateUtils.isDate(startDateStr.trim())){
			Date startDate = DateUtils.parseDate(startDateStr, "yyyy-MM-dd");
			cycleMainInfo.setStartDate(startDate);
		}else{
			throw new RuntimeException("开始日期格式异常！");
		}
		String endDateStr = cycleMainInfo.getEndDateStr();
		if(DateUtils.isDate(endDateStr.trim())){
			Date endDate = DateUtils.parseDate(endDateStr, "yyyy-MM-dd");
			cycleMainInfo.setEndDate(endDate);
		}else{
			throw new RuntimeException("截止日期格式异常！");
		}
		if(cycleMainInfo.getStartDate().getTime()>cycleMainInfo.getEndDate().getTime()){
			throw new RuntimeException("截止日期不能早于开始日期！");
		}
		CycleMain cycleMain = new CycleMain();
		BeanUtils.copyProperties(cycleMainInfo, cycleMain);
		List<CycleMain> cycleMainListDB = cycleMainDao.findByParamSelective(cycleMain);
		for(CycleMain cm :cycleMainListDB){
			if("create".equals(param)||(!cm.getId().equals(id))){
				throw new RuntimeException("已存在相同配置的周期！");
			}
		}
		return cycleMain;
		
	}
	
	// 根据orgId、bookId、queryDate 获取学习进度中当前阅读天数及总阅读天数  及百分比
	public Object findCycleDetail(CycleMain cycleMain) {
		
		//CycleDetail cycleDetail = new CycleDetail();
		
		List<CycleDetail> cycleDetailList = cycleDetailDao.selectReadCycle(cycleMain);
		
		// 获取当前学习计划总阅读天数
		CycleMain cycleMainDomain = new CycleMain();
//		SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM");
//		Date dQueryMonth = cycleMain.getQueryDate();
//		String strQueryMonth = sdfMonth.format(dQueryMonth);
//		cycleMainDomain.setStrQueryMonth(strQueryMonth);
		SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
		Date dQueryDay = cycleMain.getQueryDate(); // 查询日期
		String strQueryDay = sdfDay.format(dQueryDay);
		cycleMainDomain.setStrQueryDay(strQueryDay);
		Integer nTotalDayCnt = cycleDetailDao.selectReadCycleDayCnt(cycleMainDomain);
		
		List<CycleDetailDTO> cycleList = new ArrayList<CycleDetailDTO>();
		
		for (CycleDetail cycleDetail: cycleDetailList) {
			//CycleDetail cycle = new CycleDetail();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String strTaskDate = sdf.format(cycleDetail.getTaskDate());
			
			// 获取总阅读天数
			int nSize = cycleDetailList.size();
			CycleDetail cycle = cycleDetailList.get(nSize-1);
			Integer cycleDate = cycle.getTaskOrder();
			cycleDetail.setCycleDate(cycleDate);
			// 当前阅读天数
			int curTaskDate = cycleDetail.getTaskOrder().intValue();
			int nCycleDate = cycleDate.intValue();
			NumberFormat numberFormat = NumberFormat.getInstance();
			numberFormat.setMaximumFractionDigits(2);
			String rate = numberFormat.format((float)curTaskDate/(float)nCycleDate);
			
			CycleDetailDTO cycleDetailDTO = 
					ClonePojoUtil.copyClassFromTo(cycleDetail, CycleDetailDTO.class);
			// 阅读百分比
			cycleDetailDTO.setReadRate(rate);
			cycleDetailDTO.setStrTaskDate(strTaskDate);
			
			// 总阅读天数
			cycleDetailDTO.setnTotalTaskDate(nTotalDayCnt);
			cycleList.add(cycleDetailDTO);
			
		}
		/*if (cycleDetailList != null && !cycleDetailList.isEmpty()) {
			cycleDetail = cycleDetailList.get(0);
		}*/
		return cycleList;
	}
	
	// 根据 月份、userId 查询学习计划
	@Override
	public Object findCycleDetailById(CycleDetailDTO cycleDetailDTO) {

		Date dQueryDate = cycleDetailDTO.getQueryDate();
		String strQueryDate = "";
		if (dQueryDate != null) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			strQueryDate = sdf.format(dQueryDate);
		}
		
		//cycleDetailDTO.setQueryDate(dQueryDate);
		cycleDetailDTO.setStrQueryDate(strQueryDate);
		
		List<CycleDetail> cycleDetailList = cycleDetailDao.selectCycleById(cycleDetailDTO);
		
		StudyCycleDTO studyCycleDTO = new StudyCycleDTO();
		
		List<String> taskDateList = new ArrayList<String>();
		
		if (cycleDetailList != null && !cycleDetailList.isEmpty()) {
			
			for (CycleDetail cycle: cycleDetailList) {
				
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				// 只显示当天及之前的阅读日期
				if (cycle.getTaskDate().before(new Date())
						|| cycle.getTaskDate() == new Date()) {
					String strTaskDate = sdf.format(cycle.getTaskDate());
					//dto.setStrTaskDate(strTaskDate);
					taskDateList.add(strTaskDate);
				}
				
			}
		}
		studyCycleDTO.setStrTaskDateList(taskDateList);
		
		// 根据userId 查询orgId
		String userId = cycleDetailDTO.getUserId();
		User user = (User) userDao.selectByPrimaryKey(userId);
		// 根据orgId 查询所有parentOrgId
		JSONResult pOrgJson = (JSONResult) orgService.getParentOrgId(user.getUserOrg());
		String pOrgId = pOrgJson.getResultBean();
		
		String [] orgIds = pOrgId.split(",");
		
		List<String> orgIdList = new ArrayList<String>();
		
		for (int i = 0; i < orgIds.length; i++) {
			String orgId = orgIds[i];
			orgIdList.add(orgId);
		}
		orgIdList.add(user.getUserOrg());
		// 去重
		DataCommUtil.removeDup(orgIdList);
		// 查询当月考试日期
		//Date queryDate = cycleDetailDTO.getQueryDate();
		List<ExamCircleDTO> circleList = circleDao.findExamDateByMonth(orgIdList, strQueryDate);
		
		List<String> examDateList = new ArrayList<String>();
		
//		Date dMinBeginDate = null;
//		Date dMaxEndDate = null;
		
		if (circleList != null && !circleList.isEmpty()) {
			for (ExamCircleDTO dto: circleList) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				// 判断考试开始日期与结束日期为同一天时
				
				if (dto.getBeginDate().compareTo(dto.getEndDate()) == 0) {
					
					// 当天日期
					Date dNowDate = new Date();
					String strNowDate = sdf.format(dNowDate);
					try {
						dNowDate = sdf.parse(strNowDate);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						log.error("日期转换失败：" + e.getMessage());
					}
					// 只显示当天及之后的考试日期
					if (dto.getBeginDate().compareTo(dNowDate) >= 0) {
						String strExamDate = sdf.format(dto.getBeginDate());
						examDateList.add(strExamDate);
					}
				}
				
				
				
//				if (dMinBeginDate == null || 
//						dto.getBeginDate().before(dMinBeginDate)
//						|| dto.getBeginDate() == dMinBeginDate) {
//					dMinBeginDate = dto.getBeginDate();
//				}
//				if (dMaxEndDate == null ||
//						dto.getEndDate().after(dMaxEndDate)
//						|| dto.getEndDate() == dMaxEndDate) {
//					dMaxEndDate = dto.getEndDate();
//				}
			}
		}
		
//		if (dMinBeginDate != null && dMaxEndDate != null) {
//			// 考试最小开始日期、最大结束日期
//			Calendar calMinDate = Calendar.getInstance();
//			Calendar calMaxDate = Calendar.getInstance();
//			// 只显示当天及之后的考试日期
//			
//			if (dMinBeginDate.after(new Date())
//					|| dMinBeginDate == new Date()) {
//				calMinDate.setTime(dMinBeginDate);
//			}
//			if (dMaxEndDate.after(new Date())
//					|| dMaxEndDate == new Date()) {
//				calMaxDate.setTime(dMaxEndDate);
//			}
//			
//			examDateList = DataCommUtil.printDay(calMinDate, calMaxDate);
//		}
	
		studyCycleDTO.setStrExamDateList(examDateList);
		
		// 根据查询月份查询已签到日期
		BaseSignDTO baseSignDTO = new BaseSignDTO();
		baseSignDTO.setUserId(userId);
		baseSignDTO.setStrQueryMonth(strQueryDate);
		List<BaseSignDTO> signList = baseSignDao.findSignDate(baseSignDTO);
		List<String> signDateList = new ArrayList<String>();
		
		if (signList != null && !signList.isEmpty()) {
			for (BaseSignDTO dto: signList) {
//				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String strSignDate = dto.getStrSignTime();
				signDateList.add(strSignDate);
			}
		}
		
		studyCycleDTO.setStrSignDateList(signDateList);
		
		return studyCycleDTO;
	}
	
	// 保存用户卡片阅读时间
	@Override
	public Object saveReadCardTime(BaseTimeDTO baseTimeDTO) {
		
		CheckParamUtil.checkFieldIfNotBlank(baseTimeDTO, 
				"userId", "cardId", "strStartTime", "strEndTime" , "taskDay");
		// 根据userId 获取orgId
		String orgId = "";
		String userId = baseTimeDTO.getUserId();
		User user = (User) userDao.selectByPrimaryKey(userId);
		orgId = user.getUserOrg();
		
		// 计算阅读时长
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		SimpleDateFormat sdfTaskDay = new SimpleDateFormat("yyyy-MM-dd");
		
		Date dBgnTime = null;
		Date dEndTime = null;
		Date dTaskDay = null;
		
		try {
			dBgnTime = sdf.parse(baseTimeDTO.getStrStartTime());
			dEndTime = sdf.parse(baseTimeDTO.getStrEndTime());
			// 学习任务日期
			dTaskDay = sdfTaskDay.parse(baseTimeDTO.getTaskDay());
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			log.error("日期转换失败！");
			throw new BusinessException(BusinessExceptionCode.parse_format_error, "日期转换失败");
		}
		// 根据 cardId 查询该卡片阅读最小时间及最大时间 cardMin, cardMax
		BookCard bookCard = new BookCard();
		bookCard.setCardId(baseTimeDTO.getCardId());
		
		BookCard cardInfo = cardManagerDao.getBookCardInfo(bookCard);
		
		int nCardMin = 0;
		int nCardMax = 0;
		
		if (cardInfo != null && cardInfo.getCardMin() != null 
				&& cardInfo.getCardMax() != null) {
			Integer cardMin = cardInfo.getCardMin();
			Integer cardMax = cardInfo.getCardMax();
			nCardMin = cardMin.intValue();
			nCardMax = cardMax.intValue();
		}
		
		long bwTime = (dEndTime.getTime() - dBgnTime.getTime())/1000;
		Long bTime = Long.valueOf(bwTime);
		int nTime = bTime.intValue();
		// 如果读书时间在最大时间与最小时间之间，则有效
		// 修改为小于最大时间，则实际时间
		/*if (nTime >= nCardMin && nTime <= nCardMax) {
			baseTimeDTO.setTime(Integer.valueOf(nTime));
		}*/
		if (nTime <= nCardMax) {
			baseTimeDTO.setTime(Integer.valueOf(nTime));
		}
		// 如果读书时间超出最大时间，则取最大时间
		if (nTime > nCardMax) {
			baseTimeDTO.setTime(Integer.valueOf(nCardMax));
		}
		// 学习任务日期
//		baseTimeDTO.setStrQueryDate(strQueryDate);
		
		BaseTime baseTime = ClonePojoUtil.copyClassFromTo(baseTimeDTO, BaseTime.class);
		
		// 查询是否已存在阅读时间
//		BaseTimeDTO baseTimeDTO = new BaseTimeDTO();
//		baseTimeDTO.setUserId(userId);
//		baseTimeDTO.setCardId(baseTimeDTO.getCardId());
		baseTimeDTO.setStrQueryDate(baseTimeDTO.getTaskDay());
		Integer nReadTime = baseTimeDao.findCardIsReaded(baseTimeDTO);
		boolean bReaded = false; // 未阅读
		if (nReadTime != null && nReadTime.intValue() > 0) {
			bReaded = true;
		}
		// 阅读时间大于0且该卡片未阅读，才保存阅读记录时间
		if (baseTime.getTime() != null 
				&& baseTime.getTime().intValue() > 0
				&& bReaded == false) {
			baseTime.setdTaskDay(dTaskDay); // 学习任务日期 
			baseTimeDao.insertSelective(baseTime);
			
			// 插入完成学分详情表
			String type = "0001";
			Integer score = scoreSetDAO.findScoreByType(type);
			
			ScoreDetailDomain entity = new ScoreDetailDomain();
			entity.setId(UUIDUtils.create());
			entity.setType(type);
			entity.setOrgId(orgId);
			entity.setUserId(userId);
			entity.setScore(score);
			entity.setCreatUser(userId);
			entity.setCreatTime(new Date());
			entity.setModifyUser(userId);
			entity.setModifyTime(new Date());
			
			scoreDetailDAO.save(entity);
		}
		
		
		return null;
	}
	
	// 根据 orgId 查询学习计划中书籍列表
	@Override
	public Object findCycleBookList(String userId, Integer currentPage, Integer pageSize) {
		
		if (userId == null || userId.isEmpty()) {
			throw new BusinessException(BusinessExceptionCode.param_error, "用户ID不能为空！");
		}
		// 根据userId 获取orgId
		String orgId = "";
		User user = (User) userDao.selectByPrimaryKey(userId);
		orgId = user.getUserOrg();
		
		CycleMain cycleMain = new CycleMain();
		cycleMain.setOrgId(orgId);
		
		PageCond pageCond = new PageCond(currentPage,pageSize);
		
		PageCond pageCondQuery = PageCondUtil.check(pageCond);
		
		List<CycleDetail> cycleDetailList = cycleDetailDao.findBookCycle(cycleMain, pageCondQuery);
		
		List<CycleDetailDTO> dtoList = new ArrayList<CycleDetailDTO>();
		
		for (CycleDetail cycleDetail: cycleDetailList) {
			CycleDetailDTO dto = ClonePojoUtil.copyClassFromTo(cycleDetail, CycleDetailDTO.class);
			/*
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String strMinTaskDate = sdf.format(cycleDetail.getMinTaskDate());
			dto.setStrMinTaskDate(strMinTaskDate);
			
			String strMaxTaskDate = sdf.format(cycleDetail.getMaxTaskDate());
			dto.setStrMaxTaskDate(strMaxTaskDate);*/
			
			dtoList.add(dto);
		}
		
		Integer nBookCycleCnt = cycleDetailDao.findBookCycleCnt(cycleMain);
		
		pageCondQuery.setTotalCount(nBookCycleCnt);
		pageCondQuery.setPageCount(PageCondUtil.calculatePageCount(pageCondQuery));
		
		return new PageResult<CycleDetailDTO>(dtoList, pageCondQuery);
	}
	
	// 根据userId 查询首页中总阅读时间、总阅读本数、总阅读天数
	@Override
	public Object findTotalReadCycle(String userId) {
		
		BaseTimeDTO baseTimeRet = new BaseTimeDTO();
		
		// 总阅读时间
		BaseTimeDTO baseTimeDTO = new BaseTimeDTO();
		baseTimeDTO.setUserId(userId);
		
		Double dTlTime = baseTimeDao.selectTotalTime(baseTimeDTO);
		Integer nTotalTime = Integer.valueOf(0);
		if (dTlTime != null) {
			double dTotalTime = dTlTime.doubleValue();
			dTotalTime = Math.ceil(dTotalTime);
			int nTime = (int)dTotalTime;
			nTotalTime = Integer.valueOf(nTime);
		}
		baseTimeRet.setTotalReadTime(nTotalTime);
		
		// 总阅读本数与总阅读天数 只查询当前有效学习计划中的本数与天数
		// 总阅读本数
	//				Integer nTotalNum = baseTimeDao.selectTotalNum(baseTimeDTO);
	//				userFullDTO.setTotalReadNum(nTotalNum);
		CycleDetailDTO cycleDetailDTO = new CycleDetailDTO();
		cycleDetailDTO.setUserId(userId);
		
		User user = new User();
		user.setUserId(userId);
		UserDTO userDTO = userDao.selectUserInfoById(user);
		cycleDetailDTO.setOrgId(userDTO.getUserOrg());
		
		BaseTimeDTO baseTime = cycleDetailDao.findCycleBookCnt(cycleDetailDTO);
		baseTimeRet.setTotalReadNum(baseTime.getTotalReadNum());
		
		// 总阅读天数
		baseTimeRet.setTotalReadDay(baseTime.getTotalReadDay());
		
		return baseTimeRet;
	}
	
	
}
